import { useEffect, useState } from 'react';
import { META_DATA } from '@/constant/config';

export default function usePageTitle(Component: any) {
  const [pageTitle, setPageTitle] = useState<string>("")
  useEffect(() => {
    const componentTitle = (Component as any).title
    if (componentTitle) {
      setPageTitle(componentTitle)
    }
    document.title = componentTitle ? `${META_DATA.title}-${componentTitle}` : META_DATA.title
  }, [Component]);

  return { pageTitle };
}